import time

from selenium.webdriver.common.by import By
from common.Utils import BlogDriver

#测试博客详情页
class BlogDetail:
    url = ""
    driver = ""
    def __init__(self):
        self.url = "http://8.137.19.140:9090/blog_detail.html?blogId=95591"
        self.driver = BlogDriver.driver
        self.driver.get(self.url)

    #未登录状态下
    def DetailTestByFailLogin(self):
        # 画面会闪现一下，添加隐式等待
        self.driver.implicitly_wait(2)

        # 查找登录元素
        self.driver.find_element(By.CSS_SELECTOR, "body > div.container-login > div > h3")

    #登录状态下
    def DetailTestByLogin(self):
        #检查博客标题
        self.driver.find_element(By.CSS_SELECTOR, "body > div.container > div.right > div > div.title")
        #检查博客发布日期
        self.driver.find_element(By.CSS_SELECTOR, "body > div.container > div.right > div > div.date")
        #检查博客内容
        self.driver.find_element(By.CSS_SELECTOR, "#h2-u5728u8FD9u91CCu5199u4E0Bu4E00u7BC7u535Au5BA2")
        #检查”编辑“和”删除“按钮
        self.driver.find_element(By.CSS_SELECTOR, "body > div.container > div.right > div > div.operating > button:nth-child(1)")
        self.driver.find_element(By.CSS_SELECTOR, "body > div.container > div.right > div > div.operating > button:nth-child(2)")

        #检查个人信息
        self.driver.find_element(By.CSS_SELECTOR, "body > div.container > div.left > div > img")
        self.driver.find_element(By.CSS_SELECTOR, "body > div.container > div.left > div > h3")
        self.driver.find_element(By.CSS_SELECTOR, "body > div.container > div.left > div > div:nth-child(4) > span:nth-child(1)")
        self.driver.find_element(By.CSS_SELECTOR, "body > div.container > div.left > div > div:nth-child(4) > span:nth-child(2)")

        # 测试主页、写博客、注销按钮是否存在
        self.driver.find_element(By.CSS_SELECTOR, "body > div.nav > a:nth-child(4)")
        self.driver.find_element(By.CSS_SELECTOR, "body > div.nav > a:nth-child(5)")
        self.driver.find_element(By.CSS_SELECTOR, "body > div.nav > a:nth-child(6)")

